package com.yifeng.repo.base.service.impl;

import com.yifeng.base.mcs.api.MqttRestService;
import com.yifeng.base.mcs.api.dto.MqttConsumeConfigDto;
import com.yifeng.base.mcs.api.params.CompanyMsgSendParam;
import com.yifeng.base.mcs.api.params.StoreMsgSendParam;
import com.yifeng.repo.base.params.ConsoleParam;
import com.yifeng.repo.base.security.proxy.CommonProxy;
import com.yifeng.repo.base.utils.converter.JacksonHelper;

import java.util.List;

public class MqttRestServiceImpl extends CommonProxy implements MqttRestService {
    private final String mapping;

    public MqttRestServiceImpl(ConsoleParam consoleParam) {
        super(consoleParam);
        this.mapping = "/yfcloud-mcs/mqtt/rest/msg";
    }

    @Override
    public List<MqttConsumeConfigDto> listConsumeConfigByCodes(List<String> codes) {
        String url = consoleParam.getUrl() + mapping + "/config";
        String queryParameters = buildSingleQueryParameters("codes", codes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, MqttConsumeConfigDto.class);
    }

    @Override
    public Long sendCompanyMsg(CompanyMsgSendParam param) {
        String url = consoleParam.getUrl() + mapping + "/sendCompanyMsg";
        String body = JacksonHelper.toJson(param);
        return this.doActionCallByRpc(url, body, Long.class);
    }

    @Override
    public Long sendStoreMsg(StoreMsgSendParam param) {
        String url = consoleParam.getUrl() + mapping + "/sendStoreMsg";
        String body = JacksonHelper.toJson(param);
        return this.doActionCallByRpc(url, body, Long.class);
    }
}
